#include "stdafx.h"
#include <cstdio>
#include <cstdarg>
#include <locale.h>
#include <time.h>
#include "TiffLogger.h"

void Log(const wchar_t *fmt, ...)
{
    FILE* logFile = _wfopen(_T("Log.txt"), _T("a+"));
    va_list args;
    va_start(args, fmt);
    _wsetlocale(LC_CTYPE, _T("chs"));
    vfwprintf(logFile, fmt, args);
    va_end(args);
    _wsetlocale(LC_ALL, _T(""));
    fclose(logFile);
}

void Log(LOG_LEVEL level, const wchar_t *fmt, ...)
{
    FILE* logFile = _wfopen(_T("Log.txt"), _T("a+"));
    time_t rawtime;
    struct tm * timeinfo;
    char buffer[80] = {0};
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H-%M-%S:", timeinfo);
    fwrite(buffer, 1, strlen(buffer), logFile);
    va_list args;
    va_start(args, fmt);
    _wsetlocale(LC_CTYPE, _T("chs"));
    vfwprintf(logFile, fmt, args);
    va_end(args);
    _wsetlocale(LC_ALL, _T(""));
    fclose(logFile);
}

void Log(LOG_LEVEL level, const char *fmt, ...)
{
    FILE* logFile = _wfopen(_T("Log.txt"), _T("a+"));
    time_t rawtime;
    struct tm * timeinfo;
    char buffer[80] = {0};
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H-%M-%S:", timeinfo);
    fwrite(buffer, 1, strlen(buffer), logFile);
    va_list args;
    va_start(args, fmt);
    setlocale(LC_CTYPE, "chs" );
    vfprintf(logFile, fmt, args);
    va_end(args);
    setlocale(LC_ALL, "");
    fclose(logFile);
}